package com.linkage.rtcserver;

import com.linkage.rtcserver.websocket.ManyCallHandler;
import com.linkage.rtcserver.websocket.One2OneCallHandler;
import org.kurento.client.KurentoClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * Video call 1 to N demo (main).
 *
 * @author Boni Garcia (bgarcia@gsyc.es)
 * @since 5.0.0
 */
@SpringBootApplication
@EnableWebSocket
public class RtcServerApplication implements WebSocketConfigurer {

    @Value("${kms.url}")
    private String url;

    @Bean
    public KurentoClient kurentoClient() {
        System.out.println(url);
        return KurentoClient.create(url);
    }

    @Bean
    public ManyCallHandler one2ManyCallHandler(){
        return new ManyCallHandler();
    }

    @Bean
    public One2OneCallHandler one2OneCallHandler(){
        return new One2OneCallHandler();
    }


    public static void main(String[] args) {
        SpringApplication.run(RtcServerApplication.class, args);
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(one2ManyCallHandler(),"/groupCall");
        webSocketHandlerRegistry.addHandler(one2OneCallHandler(),"/oneCall");
    }
}
